﻿using System;
using System.Collections.Generic;
using UnityEngine;
using WorldMapBase.Tile;

namespace WorldMapNew
{
    /// <summary>
    /// 交通系统 路点数据
    /// </summary>
    [Serializable]
    public class TrafficNodeData
    {
        public int nodeId = 0; // 节点id
        public List<TrafficLightData> trafficLightDatas;
        public List<TrafficPointData> trafficPointDatas;

        public void addLightData(TileElement lightData, int controlRoadId1, int controlRoadId2)
        {
            if (trafficLightDatas == null) trafficLightDatas = new List<TrafficLightData>();
            TrafficLightData data = new TrafficLightData();
            data.lightData = lightData;
            data.controlRoadId1 = controlRoadId1;
            data.controlRoadId2 = controlRoadId2;
            trafficLightDatas.Add(data);
        }

        public void addPointData(int pointId,Vector3 pointVec, List<TrafficRoadPointData> roadPointDatas)
        {
            if (trafficPointDatas == null) trafficPointDatas = new List<TrafficPointData>();
            TrafficPointData data = new TrafficPointData();
            data.pointId = pointId;
            data.pointVec = pointVec;
            data.roadPointDatas = roadPointDatas;
            trafficPointDatas.Add(data);
        }
    }

    /// <summary>
    /// 交通系统 路灯数据
    /// </summary>
    [Serializable]
    public class TrafficLightData
    {
        public TileElement lightData;
        public int controlRoadId1 = 0;
        public int controlRoadId2 = 0;
    }

    /// <summary>
    /// 交通系统 坐标点数据
    /// </summary>
    [Serializable]
    public class TrafficPointData
    {
        public int pointId = 0;
        public Vector3 pointVec;
        public List<TrafficRoadPointData> roadPointDatas;
    }

    /// <summary>
    /// 交通系统 中间点数据
    /// </summary>
    [Serializable]
    public class TrafficRoadPointData
    {
        public int lineId = 0;// 其实就是A -> B 线段的B的pointId
        public List<Vector3> roadPoints;
    }

    /// <summary>
    /// 交通系统 路线数据
    /// </summary>
    [Serializable]
    public class TrafficLineData
    {
        public int nodeId = 0; // 节点id
        public int pointId = 0; // 坐标系id
    }

    [Serializable]
    public class TrafficLineDataOne
    {
        public List<TrafficLineData> trafficLineDataOne;
    }

    /// <summary>
    /// 地图块交通系统数据
    /// </summary>
    public class MapChunckTrafficData : ScriptableObject
    {
        public List<TrafficNodeData> trafficNodeDatas = new List<TrafficNodeData>();
        public List<TrafficLineDataOne> trafficLineDatas = new List<TrafficLineDataOne>();
    }

    // 运行时数据

    public struct MapChunckTrafficRunData
    {
        public List<TrafficObject> cars;
        public Dictionary<int, Dictionary<int, float>> lightState;// <nodeId,<side1 * 10 + side2, time>>  [0~8) 绿灯 [8~10) 黄灯 [10~16) 红灯
        public Dictionary<int, TrafficObject> lights; // key = nodeId_side1 * 10 + side2
        public MapChunckTrafficTileRunData tileData;
    }

    public struct MapChunckTrafficPointRunData
    {
        public int pointId;
        public Vector3 pointVec3;
        public Dictionary<int, TrafficRoadPointData> roadPointDatas;
    }
    public struct MapChunckTrafficTileRunData
    {
        public Dictionary<int, Dictionary<int, MapChunckTrafficPointRunData>> trafficNodeDatas; // <nodeId,<pointId,pointRunData>>
        public Dictionary<int, List<TrafficLightData>> trafficLightDatas; // <nodeId,List<TrafficLightData>>
        public List<TrafficLineDataOne> trafficLineDatas;
    }
}